home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Ham⁄GPS / SoftKiss.src.1.8 Folder / SoftKiss.src.1.8 / core / sfk_core_read_write.c < prev    next >
Text File  |  1992-07-15  |  2KB  |  77 lines

  1. /*
  2.  * SoftKiss drivre read/write packet routines
  3.  * by Aaron Wohl / N3LIW (aw0g+@andrew.cmu.edu) jul 1990
  4.  * 6393 Penn Ave #303
  5.  * Pittsburgh PA, 15206
  6.  * work: (412)-268-5032
  7.  * home: (412)-731-6159
  8.  */
  9.  
  10. #include "sfk_core.h"
  11. #include "sfk_core_private.h"
  12. #include <asm.h>
  13.  
  14. /*
  15.  * queue up a packet for write and start transmit if it isn't
  16.  * already running
  17.  */
  18. void sfk_enqueue_write(sfk_prt_pt p,sfk_packet_pt pak)
  19. {
  20.     sfk_SCC_interupts_off;
  21.     sfk_enqueue(&p->sfk_xmitq,pak);
  22.     sfk_initiate_xmit(p);
  23.     sfk_SCC_interupts_on;
  24. }
  25.  
  26. /*
  27.  * enqueue a packet in a write queue
  28.  */
  29. void sfk_write(sfk_iio_pt cmd)
  30. {
  31.   int i;
  32.   for(i=0;i<sfk_NUM_PORTS;i++) {
  33.     sfk_prt_pt p=sfk_PN(i);
  34.     sfk_packet_pt pak;
  35.     long real_cnt;
  36.     if(!p->sfk_IVAR(online))
  37.         continue;
  38.     if(p->pnum!=cmd->uio->do_this.cknd.sfk_rw.portno)
  39.         continue;
  40.     pak=sfk_allocate_protected(p);
  41.     if(pak==0)continue;
  42.     /*copy over packet header*/
  43.     memcpy(pak,&cmd->uio->do_this.cknd.sfk_rw,OFFSET(sfk_packet,data));
  44.     real_cnt=sfk_imin(cmd->uio->do_this.cknd.sfk_rw.cnt,p->sfk_IVAR(max_packet_size));
  45.     if(real_cnt>0)
  46.       memcpy(pak->data,cmd->uio->do_this.cknd.sfk_rw.data,real_cnt);
  47.     sfk_enqueue_write(p,pak);
  48.     return;
  49.   }
  50.   sfk_control_fail(cmd,0,sfk_NO_SUCH_PORT);
  51. }
  52.  
  53. /*
  54.  * read a packet from recieve queues
  55.  */
  56. void sfk_read(sfk_iio_pt cmd)
  57. {
  58.   int i;
  59.   for(i=0;i<sfk_NUM_PORTS;i++) {
  60.     sfk_prt_pt p=sfk_PN(i);
  61.     sfk_packet_pt pak;
  62.     long real_cnt;
  63.     if(!p->sfk_IVAR(online))
  64.         continue;
  65.     pak=sfk_dequeue_protected(&p->sfk_recvq);
  66.     if(pak==0)continue;
  67.     /*copy over packet header*/
  68.     memcpy(&cmd->uio->do_this.cknd.sfk_rw,pak,OFFSET(sfk_packet,data));
  69.     real_cnt=sfk_imin(pak->cnt,p->sfk_IVAR(max_packet_size));
  70.     if(real_cnt>0)
  71.       memcpy(cmd->uio->do_this.cknd.sfk_rw.data,pak->data,real_cnt);
  72.     sfk_free_packet_protected(p,pak);
  73.     return;
  74.   }
  75.   sfk_control_fail(cmd,0,sfk_NOTHING_TO_READ);
  76. }
  77.